var express = require('express');
var router = express.Router();
var Mock = require("mockjs")
/* GET home page. */
// 商品购买历史的接口
router.use('/', function (req, res, next) {
    let pageNumber = req.body.pageNumber || 1;
    let pageSize = req.body.pageSize || 10;
    // 拓展mockjs
    Mock.Random.extend({
        state: function () {
            var phonePrefixs = ['等待买家付款', '等待平台发货', '平台已发货','交易完成','交易关闭'] // 自己写前缀哈
            return this.pick(phonePrefixs) //Number()
        },
        num: function () {
            var phonePrefixs = [1,2,3] // 自己写前缀哈
            return this.pick(phonePrefixs) //Number()
        },
        price: function () {
            var phonePrefixs = [1100,1200,2000] // 自己写前缀哈
            return this.pick(phonePrefixs) //Number()
        },
        tag: function () {
            var phonePrefixs = ['托管','设备兑换券'] // 自己写前缀哈
            return this.pick(phonePrefixs) //Number()
        },
        title: function () {
            var phonePrefixs = ['锦鲤AI算力机-K1','锦鲤AI算力机-K3','锦鲤AI算力机-K2'] // 自己写前缀哈
            return this.pick(phonePrefixs) //Number()
        }
    })
    // console.log(Mock.Random.phone())
    //实现简单的分页功能
// 生成 1 - 10 个 随机手机号码
    let { data } = Mock.mock({
        
        'data|20-30': [{
            'id|+1': 1,
            'title': '@title',
            'image': '@image(\'200x100\', \'#50B347\', \'Hello\')',
            'state': '@state',
            'tag': '@tag',
            'price': '@price',
            'num': '@num'
        }],

    })
    const total = data.length;

    let tableData = data.slice((pageNumber-1)*pageSize,(pageNumber- 1)*pageSize+pageSize);

    res.json({
        code: 200,
        message: {
            total,
            pages:pageNumber
        },
        data: tableData
    });
});
module.exports = router;
